//
//  WZVisitor.swift
//  weibo
//
//  Created by mac on 16/2/24.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit
import SnapKit

protocol  VisitorDelegate: NSObjectProtocol{
    func loginBtnClick()
    func registBtnClick()
}

class WZVisitor: UIView {

   weak var delegate:VisitorDelegate?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
//  --声明协议
    func loginBtnClick(){
        delegate?.loginBtnClick()
    }
    func registeBtnClick(){
        delegate?.registBtnClick()
    }
//    设置动画
    func setAnimation(){
    
        let animation = CABasicAnimation(keyPath: "transform.rotation")
        
        animation.toValue = 2 * M_2_PI

        animation.duration = 5
        
        animation.repeatCount = MAXFLOAT
        animation.removedOnCompletion = false
        
        animationImage.layer.addAnimation(animation, forKey: nil)
    }
    
//    设置方法用来设置visitor的内部控件的属性
    func setInfo(lableText: String,image: String,animation: Bool){
        detailLable.text = lableText
        iconImage.image = UIImage(named: image)
        if animation{
            setAnimation()
        }
        else{
            animationImage.alpha = 0.001
        }
        
    }
//    将空间添加到UI并添加约束
    func setUI(){
        
        backgroundColor = UIColor(white: 237/255.0, alpha: 1)
    
//        动画图片
        addSubview(animationImage)
//        遮罩图片
        addSubview(maskImageView)
//        通用图片
        
          addSubview(iconImage )
        addSubview(detailLable)
        addSubview(registButton)
        addSubview(loginButton)
        
//       设置约束
        
        iconImage.snp_makeConstraints { (make) -> Void in
            
            make.center.equalTo(self.snp_center)
            
        }
        
        animationImage.snp_makeConstraints { (make) -> Void in
        
            make.center.equalTo(self.snp_center)
            
        }
        
        maskImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self.snp_center)
        }

        detailLable.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(animationImage.snp_bottom).offset(10)
            make.centerX.equalTo(animationImage.snp_centerX)
            make.width.equalTo(216)
            
        }
        
        registButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(detailLable.snp_left)
            make.top.equalTo(detailLable.snp_bottom).offset(10)
            
            make.width.equalTo(100)
            make.height.equalTo(30)
        }
        
        loginButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(detailLable.snp_bottom).offset(10)
            make.right.equalTo(detailLable.snp_right)
            make.width.equalTo(100)
            make.height.equalTo(30)
            
        }
        
        
    }
    
    
//    懒加载
    
    
  private  lazy var iconImage: UIImageView = {
        
        let iconImage = UIImageView()
        iconImage.image = UIImage(named: "visitordiscover_feed_image_house")
        
        return iconImage
    }()
    
  private  lazy var animationImage: UIImageView = {
    let Image = UIImageView()
        Image.image = UIImage(named: "visitordiscover_feed_image_smallicon")
        return Image
    
    }()
    
  private  lazy var detailLable: UILabel = {
    let lable = UILabel()
        lable.text = "时间带手机啊啊是打卡机圣诞卡圣诞卡深刻的坎坷机登录"
        lable.textAlignment = NSTextAlignment.Center
        
        lable.font = UIFont.systemFontOfSize(14)
        lable.numberOfLines = 0
        
        
        return lable
    }()
    
   private lazy var registButton: UIButton = {
    let btn = UIButton()
        btn.setTitle("登录", forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        btn.addTarget(self, action: "loginBtnClick", forControlEvents: .TouchUpInside)
    
        return btn
    }()
    
   private lazy var loginButton: UIButton = {
        let btn = UIButton()
        btn.setTitle("注册", forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        btn.addTarget(self, action: "registeBtnClick", forControlEvents: .TouchUpInside)
        return btn
    }()
    
    
   private lazy var maskImageView: UIImageView = {
    
        let image = UIImageView()
        image.image = UIImage(named: "visitordiscover_feed_mask_smallicon")
        
        return image
        
    }()

}


